package com.wcy.controller.perm;

import com.wcy.annotation.aop.PreAuth;
import com.wcy.entity.SrMenu;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.perm.FeignMenuService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MenuController {
    @Resource
    private FeignMenuService feignMenuService;

    @GetMapping("menu/page")
    public ResponseEntity<PageData<SrMenu>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                     @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(SrMenu.class,feignMenuService.getPage(pageNum, pageSize).getBody(),  new ApiDescriptor("menu/add", "menu/update", "menu/delete","", "menu/list"), ColumnConstructor.create()));
    }

    @GetMapping("menu/list")
    public ResponseEntity<List<SrMenu>> getList(){
        return feignMenuService.getList();
    }

    @PostMapping("menu/add")
    public ResponseEntity<Void> add(@RequestBody SrMenu srMenu){
        return feignMenuService.add(srMenu);
    }

    @PutMapping("menu/update")
    public ResponseEntity<Void> update(@RequestBody SrMenu srMenu){
        return feignMenuService.update(srMenu);
    }

    @DeleteMapping("menu/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id){
        return feignMenuService.delete(id);
    }

    @GetMapping("menu/authenticated/list")
    public ResponseEntity<List<SrMenu>> getUserMenuList(){
        return feignMenuService.getUserMenuList();
    }
}
